package com.synjones.handsetS8;

/**
 * Created by zhaodianbo on 2016-7-19.
 */

import android.os.IBinder;
import android.os.IWtWdPowerService;
import android.os.RemoteException;
import android.util.Log;

import java.lang.reflect.Method;

public class S8PowerControl {

    public static boolean COMPATIBLE_WITH_OLD_MACHINE=false;

/*    private IWtWdPowerService mService;
    public static volatile S8PowerControl s8PowerControl;


    private S8PowerControl() {
        try{
            Object object = new Object();
            Method getService = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
            Object obj = getService.invoke(object, new Object[]{new String("wtwd_power")});
//System.out.println(obj.toString());
            mService = IWtWdPowerService.Stub.asInterface((IBinder)obj);
        }catch(Exception ex){
//ignored
        }
        //mService = IWtWdPowerService.Stub.asInterface(ServiceManager.getService("wtwd_power"));
        if(mService == null){
            Log.e("wtwd", " Remote Manager: no remote service.");
        }
    }

    public static S8PowerControl getInstance(){
        if(s8PowerControl==null){
            synchronized (S8PowerControl.class){
                if(s8PowerControl==null)
                    s8PowerControl=new S8PowerControl();
            }
        }
        return s8PowerControl;
    }

    public int getFingerPowerStatus(){
        if(mService==null) return -1;
        try {
            return mService.getFingerPower() ;
        } catch (RemoteException e) {
        }
        return 0;
    }

    public int setFingerPowerOn(){
        return setPower(0);
    }

    public int setFingerPowerOff(){
        return setPower(1);
    }

    public int setPower(int val){
        if(mService==null) return -1;
        try {
            return mService.setPower(val);
        } catch (RemoteException e) {
        }
        return 0;
    }

    public int getIDReaderPowerStatus(){
        if(mService==null) return -1;
        try {
            return mService.getIDPower() ;
        } catch (RemoteException e) {
        }
        return 0;
    }

    public int setIDReaderPowerOn(){
        return setPower(2);
    }
    public int setIDReaderPowerOff(){
        return setPower(3);
    }

    public int getWtWdPowerState(int cmd)
    {
        try {
            return this.mService.getWtWdPowerState(cmd);
        }
        catch (RemoteException localRemoteException) {
        }
        return 0;
    }
*/

}
